﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>排产池维护</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
    <style>
        .easyui-linkbutton
        {
            margin-left: 20px;
        }
        table tr td
        {
            padding: 0px 5px;
        }
        #ApsPoolForm
        {
            padding: 10px 0px;
        }
        .priority
        {
            margin: 0 10px;
        }
        .fontRight
        {
            text-align: right;
            padding: 5px 0;
            display: grid;
        }
    </style>
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <form id="searchForm" method="post">
            <table>
                <tr class="divLabel">
                    <td>
                        分厂:
                    </td>
                    <td>
                        计划员:
                    </td>
                    <td>
                        是否启用:
                    </td>
                    <td>
                        优先级策略:
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="selFactory" name="Factory" class="easyui-combobox" style="width: 150px;
                            height: 22px" />
                    </td>
                    <td>
                        <input id="employee" name="Employee" class="easyui-textbox" style="width: 120px;
                            height: 22px" />
                    </td>
                    <td>
                        <input id="isUse" name="IsUse" class="easyui-combobox IsUsee" style="width: 120px;
                            height: 22px" data-options='editable:false' />
                    </td>
                    <td>
                        <input id="priority" name="Priority" class="easyui-combobox" style="width: 150px;
                            height: 22px" data-options='editable:false,multiple:true' />
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a>
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">
                            重置</a>
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="排产池维护" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <table id="ApsPool" style="height: 440px; width: 100%" data-options="rownumbers:true">
            </table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            group:'paging-tail-btns',
                            id:'pageGo'
                    }]
                ">
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="按钮区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <a href="javascript:void(0)" onclick="page.AddApsPool()" class="easyui-linkbutton"
                data-options="width:120" style="margin: 10px 0 10px 20px;">添加</a> <a href="javascript:void(0)"
                    onclick="page.EditeApsPool()" class="easyui-linkbutton" data-options="width:120"
                    style="margin: 10px 0 10px 20px;">编辑</a> <a href="javascript:void(0)" onclick="page.DeleteApsPool()"
                        class="easyui-linkbutton" data-options="width:120" style="margin: 10px 0 10px 20px;">
                        删除</a> <a href="javascript:void(0)" onclick="page.EnableOrStopUseApsPool()" class="easyui-linkbutton"
                            data-options="width:120" style="margin: 10px 0 10px 20px;">启用/停用</a>
            <a href="javascript:void(0)" onclick="page.AddApsPoolTimeRule()" class="easyui-linkbutton"
                data-options="width:120" style="margin: 10px 0 10px 20px;">维护开始规则</a> <a href="javascript:void(0)"
                    onclick="page.AddInfiniteApsPool()" class="easyui-linkbutton" data-options="width:120"
                    style="margin: 10px 0 10px 20px;">添加无限排产池</a>
        </div>
    </div>
    <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px">
    </div>
    <div id="dd" style="display: none">
        <form id="ApsPoolForm" method="post">
        <table>
            <tr class="priority">
                <td class="fontRight">
                    排产池:
                </td>
                <td>
                    <input id="Text1" name="APSPOOLNAME" class="easyui-textbox" style="width: 260px;
                        height: 22px" /><input type="hidden" name="APSPOOLID" id="ApsPoolID" />
                </td>
                <td class="fontRight">
                    分厂:
                </td>
                <td>
                    <input id="FACTORY" name="FACTORY" class="easyui-textbox" style="width: 260px; height: 22px"
                        readonly />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    计划员:
                </td>
                <td>
                    <input id="Text3" name="EMPLOYEE" class="easyui-combobox" style="width: 260px; height: 22px"
                        data-options='multiple:true' />
                </td>
                <td class="fontRight">
                    是否启用:
                </td>
                <td>
                    <input id="Text4" name="ISUSE" class="easyui-combobox IsUse" style="width: 260px;
                        height: 22px" value="0" />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    组织范围:
                </td>
                <td colspan="3">
                    <input id="WORKCENTER" name="WORKCENTER" class="easyui-combobox" style="width: 593px;
                        height: 22px" data-options='multiple:true' />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    预排产期:
                </td>
                <td>
                    <input id="Text6" name="TRYCYCLE" class="easyui-numberbox" style="width: 260px; height: 22px"
                        data-options="" />
                </td>
                <td class="fontRight">
                    正排产期:
                </td>
                <td>
                    <input id="Text7" name="OFFICIALCYCLE" class="easyui-numberbox" style="width: 260px;
                        height: 22px" data-options="" />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    排产规则:
                </td>
                <td>
                    <select id="ddlApsRule" name="apsRule" class="easyui-combobox" style="width: 260px;
                        height: 22px" data-options='value:""'>
                        <option value="1">机加工序排产（2023版）</option>
                        <option value="2">热表工序排产（2024版）</option>
                    </select>
                </td>
            </tr>
            <tr class="">
                <td class="fontRight">
                    优先级策略:
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div>
                        <table id="PriorityTable">
                        </table>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="4" style="text-align: right; padding-top: 10px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.SaveApsPoolData()">
                        确定</a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dd').dialog('close')">
                            取消</a>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <span id="message" style="color: red"></span>
                </td>
            </tr>
        </table>
        </form>
    </div>
    <!--维护开始规则-->
    <div id="rule" style="display: none">
        <form id="ApsPoolTimeRuleForm" method="post">
        <table>
            <tr class="priority">
                <td class="fontRight">
                    排产池:
                </td>
                <td>
                    <input id="Text2" name="APSPOOLNAME" class="easyui-textbox" style="width: 270px;
                        height: 22px" disabled="disabled" />
                </td>
                <td class="fontRight">
                    分厂:
                </td>
                <td>
                    <input id="Text5" name="FACTORYNAME" class="easyui-textbox" style="width: 270px;
                        height: 22px" disabled="disabled" />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    计划员:
                </td>
                <td>
                    <input id="Text8" name="EMPLOYEENAME" class="easyui-textbox" style="width: 270px;
                        height: 22px" disabled="disabled" />
                </td>
                <td class="fontRight">
                    是否启用:
                </td>
                <td>
                    <input id="Text9" name="ISUSE" class="easyui-textbox IsUse" style="width: 270px;
                        height: 22px" disabled="disabled" />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    组织范围:
                </td>
                <td colspan="3">
                    <input id="Text10" name="WORKCENTER" class="easyui-combobox" style="width: 613px;
                        height: 22px" disabled="disabled" />
                </td>
            </tr>
            <tr class="priority">
                <td class="fontRight">
                    预排产期:
                </td>
                <td>
                    <input id="Text11" name="TRYCYCLE" class="easyui-numberbox" style="width: 270px;
                        height: 22px" disabled="disabled" />
                </td>
                <td class="fontRight">
                    正排产期:
                </td>
                <td>
                    <input id="Text12" name="OFFICIALCYCLE" class="easyui-numberbox" style="width: 270px;
                        height: 22px" disabled="disabled" />
                </td>
            </tr>
            <tr class="">
                <td class="fontRight">
                    正排策略:
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div>
                        <table id="ApsPoolTimeRuleTable">
                        </table>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="font-size: 12px; color: red">
                    *注：当以上条件均不生效时取订单开始时间
                </td>
                <td colspan="2" style="text-align: right; padding-top: 10px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.SaveApsPoolTimeData()">
                        确定</a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#rule').dialog('close')">
                            取消</a>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <span id="Span1" style="color: red"></span>
                </td>
            </tr>
        </table>
        </form>
    </div>
    <!--添加无限排产池-->
    <div id="inApsPool" style="display: none">
        <form id="inApsPoolForm" method="post">
        <table>
            <tr class="priority">
                <td class="fontRight">
                    无限产期:
                </td>
                <td>
                    <input id="isf_InfiniteCycle" name="infiniteCycle" class="easyui-numberbox" style="width: 260px;
                        height: 22px" data-options="" />
                </td>
            </tr>
            <tr>
                <td colspan="4" style="text-align: right; padding-top: 10px">
                    <a id="isf_BtnSave" href="javascript:void(0)" class="easyui-linkbutton">确定</a> <a
                        id="isf_BtnClose" href="javascript:void(0)" class="easyui-linkbutton">取消</a>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <span id="Span2" style="color: red"></span>
                </td>
            </tr>
        </table>
        </form>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    //创建人：longb
    //日期：2023-02-14
    //描述：排产池维护
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        editIndex:null,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsPoolHandler.ashx",
        PriorityData: [{ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 1, PRIORITYNAME: '订单优先级', PRIORITYDESC: '订单的优先级，1~9从大到小',EDITESEQUENCE:'' },
                      { ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 2, PRIORITYNAME: '最早交货期', PRIORITYDESC: '订单的要求完成时间从早到晚',EDITESEQUENCE:'' },
                      { ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 3, PRIORITYNAME: '加工时间长优先', PRIORITYDESC: '按照工序期量计算批次加工时长（h）从大到小',EDITESEQUENCE:'' },
                      { ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 4, PRIORITYNAME: '加工时间短优先', PRIORITYDESC: '按照工序期量计算批次加工时长（h）从小到大',EDITESEQUENCE:'' },
                      { ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 5, PRIORITYNAME: '涉及瓶颈设备优先', PRIORITYDESC: '工艺期量中是否包含瓶颈设备',EDITESEQUENCE:'' },
                      { ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 6, PRIORITYNAME: '临界比小优先', PRIORITYDESC: '订单的批次剩余时间/剩余未加工工序需求时间h',EDITESEQUENCE:''}],

        PriorityData2:[{ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 10, PRIORITYNAME: '连续加工优先', PRIORITYDESC: '当流卡涉及连续加工(有下工序)',EDITESEQUENCE:''},
        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 11, PRIORITYNAME: '转工放行优先', PRIORITYDESC: '在转工放行清单中的批次',EDITESEQUENCE:''},
        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 12, PRIORITYNAME: '加工时间短优先', PRIORITYDESC: '按照工步期量计算批次加工时长（h）从小到大',EDITESEQUENCE:''},
        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 13, PRIORITYNAME: '最早交货期', PRIORITYDESC: '转工计划要求完成时间从早到晚',EDITESEQUENCE:''},
        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 14, PRIORITYNAME: '温度优先', PRIORITYDESC: '工艺对应的设备温度低的优先',EDITESEQUENCE:''}
        ],

        TimeRuleData:[ {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 1, PRIORITYNAME: '手动指定开始时间', PRIORITYDESC: '手动指定开始时间作为工序开始时间',H:'0'},
                        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 2, PRIORITYNAME: '当前系统时间', PRIORITYDESC: '取当前时间+1小时作为工序开始时间',H:'1'},
                        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 3, PRIORITYNAME: '订单开始时间', PRIORITYDESC: '取订单开始时间+8小时作为工序开始时间',H:'8'},
                        {ISOPEN: false, SEQUENCE:9 , PRIORITYCODE: 4, PRIORITYNAME: '已派工计划完成', PRIORITYDESC: '取已派工计划完成+1小时作为工序开始时间',H:'1'}
            ],
        init: function () {
            page.initPageData('','');
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
            page.addEditCell();
            InApsPoolPage.bind();
        },
        addEditCell: function () //给easyuigrid新增editcell方法
        {
            $.extend($.fn.datagrid.methods, {
                editCell: function (jq, param) {
                    return jq.each(function () {
                        var opts = $(this).datagrid('options');
                        var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor1 = col.editor;
                            if (fields[i] != param.field) {
                                col.editor = null;
                            }
                        }
                        $(this).datagrid('beginEdit', param.index);
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor = col.editor1;
                        }
                    });
                }
            });
        },
         endEditing: function (gridId) {
            if (page.editIndex == undefined) { return true }
            if ($('#' + gridId).datagrid('validateRow', page.editIndex)) {
                $('#' + gridId).datagrid('endEdit', page.editIndex);
                page.editIndex = undefined;
                return true;
            } else {
                return false;
            }
        },
        initPageData: function (type,eids) {
            page.post({ action: "InitPageData",type:type,eids:eids }, true, function (res) {
                //绑定工厂下拉框
                $("#selFactory").combobox({
                    valueField: 'FACTORYID',
                    textField: 'FACTORYNAME',
                    panelHeight: 200,
                    data: res.DBTable, //下拉数据
                });
                 $('#Text3').combobox({
                    valueField: 'EMPLOYEEID',
                    textField: 'FULLNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.Table2, //下拉数据
                    onSelect: function (row) {
                        var opts = $(this).combobox('options');
                        var el = opts.finder.getEl(this, row[opts.valueField]);
                        el.find('input.combobox-checkbox')._propAttr('checked', true);
                    },
                    onUnselect: function (row) {
                        var opts = $(this).combobox('options');
                        var el = opts.finder.getEl(this, row[opts.valueField]);
                        el.find('input.combobox-checkbox')._propAttr('checked', false);
                    },
                    formatter: function (row) {
                        var opts = $(this).combobox('options');
                        return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]+'</input>';
                    },
                    onLoadSuccess:function(){
                        if(type!=''){
                        var rows=$('#ApsPool').datagrid('getChecked');
                        $('#Text3').combobox('setValues',rows[0].EMPLOYEEIDS.split(','));
                        $('#Text3').combobox('setText',rows[0].EMPLOYEENAME);
                        }
                    }
                });
                $('#WORKCENTER').combobox({
                    valueField: 'WORKCENTERID',
                    textField: 'WORKCENTERNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.Table1, //下拉数据
                    onSelect: function (row) {
                        var opts = $(this).combobox('options');
                        var el = opts.finder.getEl(this, row[opts.valueField]);
                        el.find('input.combobox-checkbox')._propAttr('checked', true);
                    },
                    onUnselect: function (row) {
                        var opts = $(this).combobox('options');
                        var el = opts.finder.getEl(this, row[opts.valueField]);
                        el.find('input.combobox-checkbox')._propAttr('checked', false);
                    },
                    formatter: function (row) {
                        var opts = $(this).combobox('options');
                        return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]+'</input>';
                    },
                    onLoadSuccess:function(){
                        if(type!=''){
                        var rows=$('#ApsPool').datagrid('getChecked');
                        $('#WORKCENTER').combobox('setValues',rows[0].WORKCENTERIDS.split(','));
                        $('#WORKCENTER').combobox('setText',rows[0].WORKCENTER);
                        }
                    }
                });
                $('#FACTORY').textbox('setValue',res.ReturnData==null?'':res.ReturnData.Factory);   
            });
            $('.IsUsee').combobox({
                valueField: 'id',
                textField: 'text',
                panelHeight: 200,
                data: [{ id: '0', text: '是' }, { id: '1', text: '否' }, { id: '', text: '全部'}]
            });
            $('.IsUse').combobox({
                valueField: 'id',
                textField: 'text',
                panelHeight: 200,
                data: [{ id: 0, text: '是' }, { id: 1, text: '否'}]
            });
            $('#priority').combobox({
                valueField: 'PRIORITYCODE',
                textField: 'PRIORITYNAME',
                panelHeight: 200,
                data:page.PriorityData,
                onSelect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', true);
                },
                onUnselect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', false);
                },
                 formatter: function (row) {
                    var opts = $(this).combobox('options');
                    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]+'</input>';
                },
            });
            
        },
        //页面事件绑定
        bind: function () {
            $('#ApsPool').datagrid({
                rownumbers: true,
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                columns: [[
                 { field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'APSPOOLNAME', title: '排产池', width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '分厂', width: 90, align: 'center' },
                 { field: 'EMPLOYEENAME', title: '计划员', width: 120, align: 'center' },
                 { field: 'ISUSE', title: '是否启用', width: 90, align: 'center',formatter: function (value, row, index) {if(value==0){return '是';}else{return '否';}}  },
                 { field: 'WORKCENTER', title: '组织范围', width: 150 , align: 'center'},
                 { field: 'PRIORITYNAME', title: '优先级策略', width: 250, align: 'center' },
                 { field: 'TIMERULENAME', title: '排产规则', width: 250, align: 'center' },
                 { field: 'TRYCYCLE', title: '预排产周期', width: 90 , align: 'center'},
                 { field: 'OFFICIALCYCLE', title: '正排产周期', width: 90, align: 'center' },
                 { field: 'INFINITECYCLE', title: '无限排产周期', width: 90, align: 'center' },
                 { field: 'LASTCHANGEEMPLOYEE', title: '修改人', width: 80, align: 'center' },
                 { field: 'LASTCHANGEDATE', title: '修改时间', width: 150 , align: 'center'},
                 { field: 'CREATEEMPLOYEE', title: '创建人', width: 80, align: 'center' },
                 { field: 'CREATEDATE', title: '创建时间', width: 150, align: 'center' }
                ]]
            });

            $('#PriorityTable').datagrid({
                singleSelect: true,
                //data: page.PriorityData,
                columns: [[
                 { field: 'ISOPEN', title: '开关', width: 70, align: 'center', formatter: function (value, row, index) { 
                        var html='<input code="' + row.PRIORITYCODE + '" data-options="" index="'+index+'" class="easyui-switchbutton sb" '+(value==true?'checked':'')+'/>';
                            return html;
                      } 
                  },//
                 { field: 'SEQUENCE', title: '顺序号', width: 60, align: 'center',formatter: function (value, row, index) {if(value>6){return '';}else{ return value};} },
                 { field: 'EDITESEQUENCE', title: '调整顺序', width: 100, align: 'center',
                     formatter: function (value, row, index) {
                        if(row.SEQUENCE<=6){
                         var str = '<a href="javascript:;" onclick="page.MoveUp(this,1)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="textbox-icon combo-arrow" icon-index="0" tabindex="-1" style="width: 17px; height: 20.4px;transform: rotate(180deg);-ms-transform: rotate(180deg); -webkit-transform: rotate(180deg);"></a>';
                         str += '<a href="javascript:;" onclick="page.MoveDown(this,1)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="textbox-icon combo-arrow" icon-index="0" tabindex="-1" style="width: 17px; height: 20.4px;"></a>';
                         str += '<a href="javascript:;" onclick="page.MoveFirst(this,1)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="easyui-layout accordion-collapse" style="width: 17px;height:20px;display:inline-block;"></a>';
                         str += '<a href="javascript:;" onclick="page.MoveLast(this,1)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="accordion-collapse accordion-expand" style="width: 17px;height:20px;display:inline-block;"></a>';
                         return str;
                         }else{
                            return '';
                         }
                     }
                 },
                 { field: 'PRIORITYNAME', title: '名称', width: 120, align: 'center' },
                 { field: 'PRIORITYDESC', title: '规则说明', width: 300 }
                ]],
                onLoadSuccess: function (data) {
                    var isopen=0;
                    var priopityData=data.rows;
                    $.each(priopityData,function(index,item){
                        if(item.ISOPEN){
                        isopen++;
                        }
                    });
                
                    $('.sb').switchbutton({//开关按钮，需要重新加载，否则无效
                        reversed: true,
                        width: '40px',
                        height: '22px',
                        onText: '开',
                        offText: '关',
                        onChange: function (checked) {
                            var index=$(this).attr('index');
                            var code=$(this).attr('code');
                            $.each(priopityData,function(index,item){
                                if(item.PRIORITYCODE==code){
                                    item.ISOPEN=checked;
                                    item.SEQUENCE=checked?isopen+1:9;
                                }
                            });
                            priopityData.sort(function(a,b){
                                if(a.SEQUENCE>b.SEQUENCE)return 1;
                                if(a.SEQUENCE<b.SEQUENCE)return -1;
                                return 0;
                            });
                            $.each(priopityData,function(index,item){
                                if(item.ISOPEN){
                                    item.SEQUENCE=index+1;
                                }else{
                                    item.SEQUENCE=9;
                                }
                            });
                            console.info(priopityData);
                            console.info(page.PriorityData);
                            $('#PriorityTable').datagrid('loadData',priopityData);
                        }
                    });
                }
            });

            $('#ApsPoolTimeRuleTable').datagrid({
                singleSelect: true,
                //data: page.PriorityData,
                columns: [[
                 { field: 'ISOPEN', title: '开关', width: 60, align: 'center', formatter: function (value, row, index) { 
                        var html='<input code="' + row.PRIORITYCODE + '" data-options="" index="'+index+'" class="easyui-switchbutton sbb" '+(value==true?'checked':'')+'/>';
                            return html;
                      } 
                  },//
                 { field: 'SEQUENCE', title: '顺序号', width: 50, align: 'center',formatter: function (value, row, index) {if(value>6){return '';}else{ return value};} },
                 { field: 'EDITESEQUENCE', title: '调整顺序', width: 100, align: 'center',
                     formatter: function (value, row, index) {
                        if(row.SEQUENCE<=4){
                         var str = '<a href="javascript:;" onclick="page.MoveUp(this,2)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="textbox-icon combo-arrow" icon-index="0" tabindex="-1" style="width: 17px; height: 20.4px;transform: rotate(180deg);-ms-transform: rotate(180deg); -webkit-transform: rotate(180deg);"></a>';
                         str += '<a href="javascript:;" onclick="page.MoveDown(this,2)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="textbox-icon combo-arrow" icon-index="0" tabindex="-1" style="width: 17px; height: 20.4px;"></a>';
                         str += '<a href="javascript:;" onclick="page.MoveFirst(this,2)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="easyui-layout accordion-collapse" style="width: 17px;height:20px;display:inline-block;"></a>';
                         str += '<a href="javascript:;" onclick="page.MoveLast(this,2)" code="' + row.PRIORITYCODE + '" index="'+index+'" class="accordion-collapse accordion-expand" style="width: 17px;height:20px;display:inline-block;"></a>';
                         return str;
                         }else{
                            return '';
                         }
                     }
                 },
                 { field: 'PRIORITYNAME', title: '名称', width: 120, align: 'center' },
                 { field: 'H', title: '+H', width: 40, align: 'center',editor: { type: 'numberbox' }, styler: function (value, row, index) { return 'background-color:yellow' } },
                 { field: 'PRIORITYDESC', title: '规则说明', width: 300 }
                ]],
                onClickCell: function (index, field) {
                    //编辑单元格
                    var row = $('#ApsPoolTimeRuleTable').datagrid('getRows')[index];
                    if (field != "H") { page.ChangeApsPoolTimeData($('#ApsPoolTimeRuleTable').datagrid('getRows'));return; }
                    if (page.endEditing('ApsPoolTimeRuleTable')) {
                        if (field == "H"&&row.ISOPEN) {
                            $('#ApsPoolTimeRuleTable').datagrid('editCell', { index: index, field: field });
                            var editor = $(this).datagrid('getEditor', { index: index, field: field }); //获取当前编辑器
                            $(editor.target).next().find('.validatebox-text').focus();
                            page.editIndex = index;
                            page.ChangeApsPoolTimeData($('#ApsPoolTimeRuleTable').datagrid('getRows'));
                        }else{
                            page.ChangeApsPoolTimeData($('#ApsPoolTimeRuleTable').datagrid('getRows'));
                        }
                    }
                },
                onLoadSuccess: function (data) {
                  page.ChangeApsPoolTimeData(data);
                }
            });

            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.GetApsPoolData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.GetApsPoolData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.reset(true, true);
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
            
            $('#ddlApsRule').combobox({
                onChange:function(newVal,oldVal){
                  if(newVal=="1" ){
                    $('#PriorityTable').datagrid('loadData',page.PriorityData);                
                  }else if (newVal=="2"){
                    $('#PriorityTable').datagrid('loadData',page.PriorityData2);                
                  }
                }
            });
        },
        //查询
        searchData: function () {
            clearMessage();
            page.pageNumber = 1;
            page.GetApsPoolData();
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            page.bind();
            clearMessage();
        },
        //查询排产池信息
        GetApsPoolData: function () {
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            data.Priority=$('#priority').combobox('getValues').join(',');
            var param = {
                action: "GetApsPoolData",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber==0?1:page.pageNumber,
                data: JSON.stringify([data])
            };
            page.post(param, true, function (res) {
                page.pagetotal = res.RowCount;
                $('#ApsPool').datagrid('loadData', res.DBTable);
            });
        },
        //保存
        SaveApsPoolData: function () {
            var frdata = $('#ApsPoolForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            data.EMPLOYEE=$('#Text3').combobox('getValues').join(',');
            data.WORKCENTER=$('#WORKCENTER').combobox('getValues').join(',');
            data.APSRULE=$('#ddlApsRule').combobox('getValue');
            var opRows=[];
            var rows=$('#PriorityTable').datagrid('getRows');
            $.each(rows,function(index,item){
                if(item.ISOPEN){
                    opRows.push(item);
                }
            });
            if (isNullOrWhiteSpaceStr(data.APSPOOLNAME)) { displayMessage('请输入排产池，再进行操作', false); return; }//
            if (data.EMPLOYEE == "") { displayMessage('请选择计划员，再进行操作', false); return; }
            if (data.WORKCENTER == "") { displayMessage('请选择组织范围，再进行操作', false); return; }
            if (data.TRYCYCLE == "") { displayMessage('请输入预排产周期，再进行操作', false); return; }
            if (data.OFFICIALCYCLE == "") { displayMessage('请输入正排产周期，再进行操作', false); return; }
            if(opRows.length==0){displayMessage('请选择优先级策略，再进行操作', false); return;}
            var param = {
                action: "SaveApsPoolData",
                data: JSON.stringify([data]),
                Prioritys: JSON.stringify(opRows)
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    $('#dd').dialog('close');
                    page.GetApsPoolData();
                }
                if(res.ReturnData){
                    $('#message').html(res.Message);
                }else{
                    displayMessage(res.Message, res.Result);
                }
            });
        },
        //添加
        AddApsPool: function () {
            page.initPageData('','');
            $('#dd').dialog({
                title: '添加排产策略',
                width: 700,
                height: 500,
                closed: false,
                cache: false,
                modal: true
            });
             $.each(page.PriorityData,function(index,item){
                item.SEQUENCE=9;
                item.ISOPEN=false;
             });
              page.PriorityData.sort(function(a,b){
                  if(a.PRIORITYCODE>b.PRIORITYCODE)return 1;
                  if(a.PRIORITYCODE<b.PRIORITYCODE)return -1;
                  return 0;
              });
             $('#message').html('');
             $('#ApsPoolForm').form('clear');
             $('#ddlApsRule').combobox('select',"1");
             //$('#PriorityTable').datagrid('loadData',[]).datagrid('loadData',page.PriorityData);
        },
        //编辑
        EditeApsPool: function () {
            var rows=$('#ApsPool').datagrid('getChecked');
            page.initPageData(rows[0].WORKCENTERIDS,rows[0].EMPLOYEEIDS);
            if(rows.length!=1){displayMessage('请选择一条排产池信息，再进行操作', false); return;}
            $('#dd').dialog({
                title: '编辑排产策略',
                width: 700,
                height: 500,
                closed: false,
                cache: false,
                modal: true
            });
            $('#ApsPoolForm').form('load',rows[0]);
            $('#Text3').combobox('setValues',rows[0].EMPLOYEEIDS.split(','));
            $('#Text3').combobox('setText',rows[0].EMPLOYEENAME);
            $('#WORKCENTER').combobox('setValues',rows[0].WORKCENTERIDS.split(','));
            $('#WORKCENTER').combobox('setText',rows[0].WORKCENTER);

            $('#ddlApsRule').combobox('select',rows[0].APSRULE);

            //处理优先策略信息
            var priorityData=$('#PriorityTable').datagrid('getData').rows; 
             $.each(priorityData,function(index,item){
                item.SEQUENCE=9;
                item.ISOPEN=false;
             });
              priorityData.sort(function(a,b){
                  if(a.PRIORITYCODE>b.PRIORITYCODE)return 1;
                  if(a.PRIORITYCODE<b.PRIORITYCODE)return -1;
                  return 0;
              }); 
               $.each(priorityData,function(index,item){
                    $.each(JSON.parse(rows[0].PRIORITYLIST),function(indexx,itemm){
                        if(item.PRIORITYCODE==itemm.PRIORITYCODE){
                         item.SEQUENCE=itemm.SEQUENCE;
                         item.ISOPEN=true;
                        }
                    });
                });
              priorityData.sort(function(a,b){
                  if(a.SEQUENCE>b.SEQUENCE)return 1;
                  if(a.SEQUENCE<b.SEQUENCE)return -1;
                  return 0;
              });
               
             $('#PriorityTable').datagrid('loadData',priorityData);
        },
        //删除
        DeleteApsPool: function () {
            var rows=$('#ApsPool').datagrid('getChecked');
            if(rows.length==0){displayMessage('请选择至少一条排产池信息，再进行操作', false); return;}
            var param = {
                action: "DeleteApsPool",
                data: JSON.stringify(rows),
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    page.GetApsPoolData();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //启用--停用
        EnableOrStopUseApsPool: function () {
            var rows=$('#ApsPool').datagrid('getChecked');
            if(rows.length==0){displayMessage('请选择至少一条排产池信息，再进行操作', false); return;}
            var param = {
                action: "EnableOrStopUseApsPool",
                data: JSON.stringify(rows),
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    page.GetApsPoolData();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //添加无限排产池 add by zhangrj 20250721
        AddInfiniteApsPool: function () {
            var row = $('#ApsPool').datagrid('getSelected');
            InApsPoolPage.init(row);
        },
        //上移一位
        MoveUp: function (obj,type) {
             var indexx=Number($(obj).attr('index'));
             var priopityData=$('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('getRows');
             if(indexx==0){return;}
             if(priopityData[indexx].ISOPEN){priopityData[indexx].SEQUENCE=priopityData[indexx].SEQUENCE-1;}
             if(priopityData[indexx-1].ISOPEN){priopityData[indexx-1].SEQUENCE=priopityData[indexx-1].SEQUENCE+1;}
              priopityData.sort(function(a,b){
                  if(a.SEQUENCE>b.SEQUENCE)return 1;
                  if(a.SEQUENCE<b.SEQUENCE)return -1;
                  return 0;
              });
              $('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('loadData',priopityData);
        },
        //下移一位
        MoveDown: function (obj,type) { 
              var priopityData=$('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('getRows');
              var isopen=0;
                    $.each(priopityData,function(index,item){
                        if(item.ISOPEN){
                        isopen++;
                        }
                    });
             var indexx=Number($(obj).attr('index'));
             if(indexx+1==isopen){return;}
             if(priopityData[indexx].ISOPEN){priopityData[indexx].SEQUENCE=priopityData[indexx].SEQUENCE+1;}
             if(priopityData[indexx+1].ISOPEN){priopityData[indexx+1].SEQUENCE=priopityData[indexx+1].SEQUENCE-1;}
              priopityData.sort(function(a,b){
                  if(a.SEQUENCE>b.SEQUENCE)return 1;
                  if(a.SEQUENCE<b.SEQUENCE)return -1;
                  return 0;
              });
              $('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('loadData',priopityData);
        },
        //移到第一位
        MoveFirst: function (obj,type) { 
             var indexx=Number($(obj).attr('index'));
             var priopityData=$('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('getRows');
             if(indexx==0){return;}
             $.each(priopityData,function(index,item){
                if(index==indexx){
                    item.SEQUENCE=1;
                }
                if(index<indexx&&item.ISOPEN){
                    item.SEQUENCE=item.SEQUENCE+1;
                }
             });
              priopityData.sort(function(a,b){
                  if(a.SEQUENCE>b.SEQUENCE)return 1;
                  if(a.SEQUENCE<b.SEQUENCE)return -1;
                  return 0;
              });
              $('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('loadData',priopityData);
        },
        //移到最后一位
        MoveLast: function (obj,type) { 
         var priopityData=$('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('getRows');
            var isopen=0;
            $.each(priopityData,function(index,item){
                if(item.ISOPEN){
                isopen++;
                }
            });
             var indexx=Number($(obj).attr('index'));
             if(indexx+1==isopen){return;}
             $.each(priopityData,function(index,item){
                if(index==indexx){
                    item.SEQUENCE=isopen;
                }
                if(index>indexx&&item.ISOPEN){
                    item.SEQUENCE=item.SEQUENCE-1;
                }
             });

              priopityData.sort(function(a,b){
                  if(a.SEQUENCE>b.SEQUENCE)return 1;
                  if(a.SEQUENCE<b.SEQUENCE)return -1;
                  return 0;
              });
              $('#'+(type==1?'PriorityTable':'ApsPoolTimeRuleTable')).datagrid('loadData',priopityData);
        },
        //维护开始规则
        AddApsPoolTimeRule:function(){
            var rows=$('#ApsPool').datagrid('getChecked');
            if(rows.length!=1){displayMessage('请选择一条排产池信息，再进行操作', false); return;}
            $('#rule').dialog({
                    title: '维护开始规则',
                    width: 710,
                    height: 400,
                    closed: false,
                    cache: false,
                    modal: true
                });
            $('#ApsPoolTimeRuleForm').form('load',rows[0]);
            var TimeRuleData=page.TimeRuleData.slice();
             $.each(TimeRuleData,function(index,item){
                item.SEQUENCE=9;
                item.ISOPEN=false;
             });
              TimeRuleData.sort(function(a,b){
                  if(a.PRIORITYCODE>b.PRIORITYCODE)return 1;
                  if(a.PRIORITYCODE<b.PRIORITYCODE)return -1;
                  return 0;
              });
              if(rows[0].TIMERULES!=null){
                  $.each(TimeRuleData,function(index,item){
                        $.each(rows[0].TIMERULES.split(','),function(indexx,itemm){
                            if(item.PRIORITYCODE==itemm){
                             item.SEQUENCE=Number(rows[0].TRSEQUENCE.split(',')[indexx]);
                             item.H=Number(rows[0].ADDTIMES.split(',')[indexx]);
                             item.ISOPEN=true;
                            }
                        });
                    });
                }
              TimeRuleData.sort(function(a,b){
                  if(a.SEQUENCE>b.SEQUENCE)return 1;
                  if(a.SEQUENCE<b.SEQUENCE)return -1;
                  return 0;
              });
            $('#ApsPoolTimeRuleTable').datagrid('loadData',[]).datagrid('loadData',TimeRuleData);
        },
        SaveApsPoolTimeData:function(){
             $('#ApsPoolTimeRuleTable').datagrid('acceptChanges');
             var mrows=$('#ApsPool').datagrid('getChecked');
             var rows=$('#ApsPoolTimeRuleTable').datagrid('getRows');
             var opRows=[];
             $.each(rows,function(index,item){
                if(item.ISOPEN){
                    opRows.push(item);
                }
            });
             if(opRows.length==0){displayMessage('请选择策略，再进行操作', false); return;}
             var param = {
                action: "SaveApsPoolTimeData",
                ApsPoolID:mrows[0].APSPOOLID ,
                data: JSON.stringify(opRows)
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    $('#rule').dialog('close');
                    page.GetApsPoolData();
                }
                if(res.ReturnData){
                    $('#message').html(res.Message);
                }else{
                    displayMessage(res.Message, res.Result);
                }
            });
        },
        ChangeApsPoolTimeData:function(data){
             var isopen=0;
                    var timeruleData=data.rows;
                    $.each(timeruleData,function(index,item){
                        if(item.ISOPEN){
                        isopen++;
                        }
                    });
                
                    $('.sbb').switchbutton({//开关按钮，需要重新加载，否则无效
                        reversed: true,
                        width: '40px',
                        height: '22px',
                        onText: '开',
                        offText: '关',
                        onChange: function (checked) {
                            var index=$(this).attr('index');
                            var code=$(this).attr('code');
                            $.each(timeruleData,function(index,item){
                                if(item.PRIORITYCODE==code){
                                    item.ISOPEN=checked;
                                    item.SEQUENCE=checked?isopen+1:9;
                                }
                            });
                            timeruleData.sort(function(a,b){
                                if(a.SEQUENCE>b.SEQUENCE)return 1;
                                if(a.SEQUENCE<b.SEQUENCE)return -1;
                                return 0;
                            });
                            $.each(timeruleData,function(index,item){
                                if(item.ISOPEN){
                                    item.SEQUENCE=index+1;
                                }else{
                                    item.SEQUENCE=9;
                                }
                            });
                            $('#ApsPoolTimeRuleTable').datagrid('loadData',timeruleData);
                        }
                    });
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },
        //post数据
        post: function (param, async, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    };
    /*
    -----无限排产池弹窗对象 add by zhangrj 20250721
    */
    var InApsPoolPage = {
        apsPoolID: "",
        //初始化弹窗
        init: function(data) {
            InApsPoolPage.apsPoolID = "";
            $("#isf_InfiniteCycle").numberbox("clear");
            if(data !== undefined && data !== null)
            {
                if (data.APSPOOLTYPE === "1") {
                    displayMessage("选择的排产池不是无限排产池", false);
                    return;
                }
                InApsPoolPage.apsPoolID = data.APSPOOLID;
                $("#isf_InfiniteCycle").numberbox("setValue",data.INFINITECYCLE);
            }
            $('#inApsPool').dialog({
                title: '添加无限排产池',
                width: 500,
                height: 300,
                closed: false,
                cache: false,
                modal: true
            });
        },
        //绑定弹窗事件
        bind: function() {
            //保存
            $("#isf_BtnSave").on('click',function(){
                InApsPoolPage.save();
            });
            //关闭
            $("#isf_BtnClose").on('click',function(){
                $('#inApsPool').dialog("close");
            })
        },
        //保存
        save: function() {
            InApsPoolPage.disableFormBtn();
            var params = {
                apsPoolID: InApsPoolPage.apsPoolID
            };
            var formData = $("#inApsPoolForm").serializeArray();
            $.each(formData, function () {
                params[this.name] = this.value;
            });
            page.post({ action: "SaveInfinitePool", params: JSON.stringify(params) },true, function (res) {
                InApsPoolPage.enableFormBtn();
                if (res.Result) {
                    $('#inApsPool').dialog("close");
                    page.searchData();
                }
                displayMessage(res.Message, res.Result);
          });
        },
        //启用弹窗按钮
        enableFormBtn: function() {
            $("#isf_BtnSave").linkbutton('enable');
            $("#isf_BtnClose").linkbutton('enable');
        },
        //禁用弹窗按钮
        disableFormBtn: function() {
            $("#isf_BtnSave").linkbutton('disable');
            $("#isf_BtnClose").linkbutton('disable');
        }
    };

    $(function () {
        page.init();
    });
</script>
